﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LLFM.CAT.Model;
using LLFM.CAT.Service;

public partial class Product_SeriesList : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        navuc.CurrentTagLevelOne = 2;
        InitData();
        InitBread();
        
    }

    private void InitData()
    {
        List<M_Series> seriesList = SeriesService.GetSeriesList(1);
        rptSeriesList.DataSource = seriesList;
        rptSeriesList.DataBind();
    }

    protected void SeriesListDataBound(object sender, RepeaterItemEventArgs e) 
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            M_Series series = (M_Series)e.Item.DataItem;
            Literal ltlDivFeature = (Literal)e.Item.FindControl("ltlDivFeature");
            Literal ltlDivFpic = (Literal)e.Item.FindControl("ltlDivFpic");
            ltlDivFeature.Text = "<div id='feature" + e.Item.ItemIndex.ToString() + "' class='feature'>";
            ltlDivFpic.Text = "<div id='f-pic" + e.Item.ItemIndex.ToString() + "' class='f-pic'>";
            Literal ltlText = (Literal)e.Item.FindControl("ltlText");
            string[] Advantages = series.Advantage.Split(new string[]{"|"},StringSplitOptions.RemoveEmptyEntries);
            ltlText.Text = string.Empty;
            for (int i = 0; i < Advantages.Length;i++)
            {
                ltlText.Text += "<li>";
                ltlText.Text += Advantages[i];
                ltlText.Text += "</li>";
            }

            Repeater rptProductsList = (Repeater)e.Item.FindControl("rptProductsList");
            Repeater rptSeriesListImageBigList = (Repeater)e.Item.FindControl("rptSeriesListImageBigList");
            List<M_Products> products = ProductsService.GetProductListBySeriesIdOrderbyIdDesc(series.Id, 1, 4);
            rptSeriesListImageBigList.DataSource = products;
            rptSeriesListImageBigList.DataBind();
            rptProductsList.DataSource = products;
            rptProductsList.DataBind();
        }
    }

    private void InitBread()
    {
        Dictionary<string, string> dic = new Dictionary<string, string>();
        dic.Add("首页", "../Index.aspx");
        dic.Add("挖机产品", "../Product/SeriesDetail.aspx");
        bread1.dic = dic;
    }
}